package com.hr.action;

import java.util.List;
import com.base.dialect.PaginationSupport;
import com.base.dao.model.Ret;
import com.base.dao.model.Grid;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.apache.commons.lang.StringUtils;
import com.base.util.JSONUtils;
import com.base.web.annotation.LoginFilter;
import org.springframework.beans.factory.annotation.Autowired;
import com.base.action.CoreController;
import com.hr.dao.model.Org;
import com.hr.dao.model.OrgExample;
import com.hr.service.OrgService;

/**
@author sun
*/
@RequestMapping("org")
@Controller
@LoginFilter
public class OrgController extends CoreController{

    @Autowired
    private OrgService orgService;

    @RequestMapping("/list")
	@ResponseBody
    public String list(Integer page, Integer rows, String orgName){
    	PaginationSupport.byPage(page, rows);
    	OrgExample example = new OrgExample();
		if(null != orgName){
			example.createCriteria().andOrgNameLike("%"+orgName+"%");
		}
		example.setOrderByClause("create_time desc");
    	List<Org> list = orgService.selectByExample(example);
      	return page(list);
    }

    @RequestMapping("/save")
	@ResponseBody
    public String save(Org org){
    	if (org.getId() == null){
    		orgService.insert(org);
    	}else{
    		orgService.updateByPrimaryKeySelective(org);
    	}
       	return ok();
    }

    @RequestMapping("/findById")
	@ResponseBody
    public String find(Integer id){
    	Org org = orgService.selectByPrimaryKey(id);
       	return ok(org);
    }

    @RequestMapping("/del")
	@ResponseBody
    public String del(String id){
    	String[] ids = id.split(",");
    	for (String str : ids){
    		orgService.deleteByPrimaryKey(Integer.parseInt(str));
    	}
       	return ok();
    }

	@RequestMapping("/orgList")
	@ResponseBody
	public List<Org> orgList(){
		OrgExample example = new OrgExample();
		example.setOrderByClause("create_time desc");
		List<Org> list = orgService.selectByExample(example);
		return list;
	}
}